//
//  CustomView.m
//  CustomView
//
//  Created by zhuchao on 16/6/22.
//  Copyright © 2016年 zhanhua. All rights reserved.
//
#import "CustomView.h"
@interface CustomView()
@end
@implementation CustomView

#pragma mark --- 重写父类是设置frame的方法，View初始化时调用
-(instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image title:(NSString *)title{
    
    if (self = [super initWithFrame:frame]) {
        _image = image;
        _title = title;
        [self createSubView];
        
    }
    return self;
}
#pragma mark -- 添加子视图
-(void)createSubView{
    _icon = [[UIImageView alloc]init];
    _icon.image = _image;
    _icon.contentMode = UIViewContentModeScaleAspectFill;
    _icon.clipsToBounds = YES;
    [self addSubview:_icon];
    
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.text = _title;
    _titleLabel.numberOfLines = 2;
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    _titleLabel.font = [UIFont systemFontOfSize:__I6Width(11)];
    [_titleLabel setTextColor:[UIColor blackColor]];
    [self addSubview:_titleLabel];
    
}
#pragma mark -- 布局
-(void)layoutSubviews{
   
    [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).with.offset(0);
        make.centerX.equalTo(self.mas_centerX).with.offset(0);
        make.width.mas_equalTo(__I6Width(90));//宽随着父视图的宽的0.7倍，动态变化，已经放缩
        make.height.mas_equalTo(__I6Height(75));//高随着父视图的高的0.7倍，动态变化，已经放缩

        
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon.mas_bottom).with.offset(__I6Height(10));
        make.left.equalTo(self.mas_left).with.offset(__I6Width(9));
        make.right.equalTo(self.mas_right).with.offset(__I6Width(-9));
        make.height.mas_equalTo(__I6Height(30));//高随着俯视图的高的0.2倍，动态变化，已经放缩

        }];
    
   
    }

@end
